﻿using Serilog;
using Serilog.Events;

namespace ConsoleApp4
{
    //不同等级,输出不同文件
    internal class Program
    {
        public static void Main()
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Error)
                    .WriteTo.File("日志Logs/error-.txt", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Warning)
                    .WriteTo.File("日志Logs/warning-.txt", rollingInterval: RollingInterval.Day))
                .WriteTo.Logger(lc => lc
                    .Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Information)
                    .WriteTo.File("日志Logs/info-.txt", rollingInterval: RollingInterval.Day))
                .WriteTo.Console()
                .CreateLogger();

            // 在这里写入日志
            Log.Error("这是一条错误日志");
            Log.Warning("这是一条警告日志");
            Log.Information("这是一条信息日志");

            Log.CloseAndFlush();
        }
    }
}
